

import requests
import re

from requests.auth import HTTPBasicAuth

# 1.allow_redirects可以关闭重定向  报一个302
# url = 'http://127.0.0.1:8000/admin/'
#
# response = requests.get(url,allow_redirects=False)
# print(response.status_code)
# print(response.text)


# 2.关闭重定向 通过两次访问 进入重定向地址
# url = 'http://127.0.0.1:8000/admin/'
# response = requests.get(url,allow_redirects=False)
# print(response.status_code)
#
# 得到重定向的地址
# print(response.headers.get('Location'))
# location = response.headers.get('Location')
#
# url = f'http://127.0.0.1:8000/{location}'
# response = requests.get(url)
# print(response.status_code)
# print(response.text)



# # 3.通过cookies进行登录  手动在页面中复制


# url = 'http://127.0.0.1:8000/admin/'
# header = {"cookie":'sessionid=3t0uhaczrco5uxedh8zwx9f6e4r6r2fi'}
# response = requests.get(url,headers=header)
# print(response.status_code)
# print(response.text)
#
#
# url = 'http://127.0.0.1:8000/admin/'
# cook = {"sessionid":'3t0uhaczrco5uxedh8zwx9f6e4r6r2fi'}
# response = requests.get(url,cookies=cook)
# print(response.status_code)
# print(response.text)


# 4.auth
url = 'http://127.0.0.1:8000/admin/'

response = requests.get(url,auth=HTTPBasicAuth('admin', '123456'))
print(response.status_code)
print(response.text)
